export default {
	/**
	 * 根据key获取数据缓存 -  异步
	 * 
	 * @author joyceZhang 迁移
	 * 
	 * @param {String} key
	 * 
	 * @return {Object}
	 */
	get(key) {
		try {
			const data = uni.getStorageSync(key);
			if (typeof data === "string" && data.indexOf('{') !== -1 && data.indexOf('}') !== -1 && data.indexOf(':') !== -1) {
				return JSON.parse(data)
			} else {
				return {}
			}
		} catch (e) {
			console.log('getStorageSync catch', key);
		}
	},
	/**
	 * 设置缓存 - 异步
	 * 
	 * @author joyceZhang 迁移
	 * @param {String} key
	 * @param {Object} data
	 */
	set(key, data) {
		if (data instanceof Object) {
			data = JSON.stringify(data)
		}
		if (data instanceof Array && String(data).indexOf('object')) {
			data = JSON.stringify(data)
		}
		try {
			uni.setStorageSync(key, data);
		} catch (e) {
			console.log('setStorageSync catch', key, data);
		}
	},
	/**
	 * 根据key删除一条缓存
	 * @author joyceZhang 迁移
	 * @param {String} key
	 */
	remove(key) {
		try {
			uni.removeStorageSync(key);
		} catch (e) {
			console.log('removeStorageSync catch', key);
		}
	},
	/**
	 * 清除用户端所用缓存
	 * @author joyceZhang 迁移
	 */
	clear() {
		try {
			uni.clearStorageSync();
		} catch (e) {
			console.log('clearStorageSync catch');
		}
	},

	/**
	 * 同步获取当前 storage 的相关信息。
	 * @author joyceZhang 迁移
	 */
	getStorageInfo() {
		try {
			return uni.getStorageInfoSync();
		} catch (e) {
			console.log('getStorageInfo catch', );
		}
	}
}
